package tank02;

import java.awt.*;
import java.util.Collection;

/**
 * 子弹类
 */
public class Bullet {

    //横坐标
    private int x;
    //竖坐标
    private int y;
    //颜色
    private Color color;
    //方向
    private int direction;
    //速度
    private int speed = 5;
    //是否删除
    private boolean removed;


    public Bullet(int x, Color color, int y, int direction, int speed, boolean removed) {
        this.x = x;
        this.color = color;
        this.y = y;
        this.direction = direction;
        this.speed = speed;
        this.removed = removed;
    }

    public Bullet() {
    }

    @Override
    public void run() {
        while (true) {
            //判断子弹方向，移动子弹
            switch (direction) {
                case Tank.DIRECTION_UP:
                    y -= speed;
                    break;
                case Tank.DIRECTION_DOWN:
                    y += speed;
                    break;
                case Tank.DIRECTION_LEFT:
                    x -= speed;
                    break;
                case Tank.DIRECTION_RIGHT:
                    x += speed;
                    break;
            }
            //判断子弹是否移动出了界面，删除子弹
            if (x < 0 || x > 600 || y < 0 || y > 800) {
                this.removed = true;
                break;
            }
            //睡眠50秒
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        this.color = color;
    }

    public int getDirection() {
        return direction;
    }

    public void setDirection(int direction) {
        this.direction = direction;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public boolean isRemoved() {
        return removed;
    }

    public void setRemoved(boolean removed) {
        this.removed = removed;
    }
}
